﻿#region Header

/*
    This file is part of NDoctor.

    NDoctor is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    NDoctor is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with NDoctor.  If not, see <http://www.gnu.org/licenses/>.
*/

#endregion Header

namespace Probel.AspTest.Domain.Components
{
    using System.Collections.Generic;
    using System.Linq;

    using log4net;

    using MongoDB.Driver;
    using MongoDB.Driver.Linq;

    using Probel.AspTest.Domain.Entities;

    internal class BaseComponent
    {
        #region Fields

        protected readonly ILog Logger;

        private static readonly string ConnectionString = "mongodb://statistics:ndoctor@ds049157.mongolab.com:49157/ndoctor-statistics";

        private readonly MongoDatabase Database;

        #endregion Fields

        #region Constructors

        public BaseComponent()
        {
            this.Logger = LogManager.GetLogger(this.GetType());
            this.Database = new MongoClient(ConnectionString)
                .GetServer()
                .GetDatabase("ndoctor-statistics");
        }

        #endregion Constructors

        #region Properties

        protected IQueryable<AnonymousUser> QueryUsers
        {
            get
            {
                return this.Database.GetCollection<AnonymousUser>("users").AsQueryable();
            }
        }

        protected IEnumerable<StatisticEntry> QueryStatistics
        {
            get
            {
                return this.Database.GetCollection<StatisticEntry>("statistics").AsQueryable();
            }
        }

        #endregion Properties
    }
}